import * as echarts from '../../ec-canvas/echarts';

const app = getApp();

function initChart(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);

  var option = {
  
    color: ["#37A2DA", "#67E0E3", "#9FE6B8"],
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data:['10/26','10/26','10/26','10/26','10/26','10/26','10/26','10/26','10/26','10/26',],
      show: true

    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
       show: false
    },
    series: [{
      type: 'line',
      label: {
        normal: {
          show: true,
          position: 'top'
        }
      },
      data: [57, 62, 58, 63, 65, 65, 65,59,59,59,51,56,59,59,59,]
    }]
  };

  chart.setOption(option);
  return chart;
}

Page({

  /**
   * 页面的初始数据
   */
  data: {
    ec: {
      onInit: initChart
    },

    content:'0',
    currentTab: 0, //预设当前项的值
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

switchTab: function(e){
     this.setData({
       currentTab: e.detail.current,
     })

  },

// 点击标题切换当前页时改变样式
swichNav: function(e) {
  if (e == 0 || e == 1 || e == 2 || e == 3 || e == 4 || e == 5){
    var cur = e
  }else{
    var cur = e.target.dataset.current;
  }
  this.setData({
    content: cur,
    swipperSpot: '0'
  })
  if (this.data.currentTab == cur) {
    if (this.data.currentTab == 0) {
      this.setData({
        zuosrc: '../../images/icon/zuojiantou.png',
        yousrc: '../../images/icon/youjiantouo.png',
      })
    } else if (this.data.currentTab == 5) {
      this.setData({
        yousrc: '../../images/icon/youjiantou.png',
        zuosrc: '../../images/icon/zuojiantouo.png',
      })
    } else {
      this.setData({
        zuosrc: '../../images/icon/zuojiantouo.png',
        yousrc: '../../images/icon/youjiantouo.png'
      })
    }
     return false;
   }else {
    this.setData({
      currentTab: cur,
      swipperSpot: '0'
    })
    app.globalData.cate_id =cur
    console.log(this.data.currentTab)
    if (this.data.currentTab==0){
      this.setData({
        zuosrc: '../../images/icon/zuojiantou.png',
        yousrc: '../../images/icon/youjiantouo.png',
      })
    } else if (this.data.currentTab == 5){
      this.setData({
        yousrc: '../../images/icon/youjiantou.png',
        zuosrc: '../../images/icon/zuojiantouo.png',
      })
    }else{
      this.setData({
        zuosrc: '../../images/icon/zuojiantouo.png',
        yousrc: '../../images/icon/youjiantouo.png'
      })
    }
  }
  this.checkCor()
},

//判断当前滚动超过一屏时，设置tab标题滚动条。
checkCor: function () {
  if (this.data.currentTab >2) {
    this.setData({
      scrollLeft: 300
    })
  } else {
    this.setData({
      scrollLeft: 0
    })
  }
},

})


 